<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>科室动态编辑</title>
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/metro/easyui.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/mobile.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/css/common.css"
	rel="stylesheet" />
<style type="text/css">
.content-tab ul {
	padding: 0px;
	margin: 0px;
}
span.datebox{
height:30px!important;
}
span.datebox span a.textbox-icon{
height:30px!important;
}
span.datebox input.textbox-text{
padding-top:8px!important;
}
</style>
</head>
<body>
	<div>
		<!--导航栏-->
		<div class="line10"></div>
		<!--/导航栏-->

		<!--内容-->
		<div id="floatHead" class="content-tab-wrap">
			<div class="content-tab">
				<div class="content-tab-ul-wrap">
					<ul>
						<li><a class="selected" href="javascript:;">科室编辑</a></li>
					</ul>
				</div>
			</div>
		</div>

		<div class="tab-content">
			<dl>
				<dt>科室编码</dt>
				<dd>
					<input id="CODE" class="input normal"></input><span
						class="Validform_checktip"> *必填</span>
				</dd>
			</dl>
			<dl>
				<dt>科室名称</dt>
				<dd>
					<input id="NAME" name="CODE" class="input normal"></input> <span
						class="Validform_checktip">*必填</span>
				</dd>
			</dl>			
			<dl>
				<dt>作者</dt>
				<dd>
					<input id="AUTHOR" class="input normal"></input>
					<span class="Validform_checktip"></span>
				</dd>
			</dl>		
			<dl>
				<dt>标题</dt>
				<dd>
					<input id="TITLE" class="input normal"></input>
					<span class="Validform_checktip">最多250个字符</span>
				</dd>
			</dl>									
			<dl>
				<dt>科室简介</dt>
				<dd>
					<textarea id="CONTENT" name="MEMO" style="width:500px;height:150px;" class="input"></textarea>
					<span class="Validform_checktip">最多2000个字符</span>
				</dd>
			</dl>			
		</div>
		<!--/内容-->

		<!--工具栏-->
		<div class="page-footer">
			<div class="btn-wrap">
				<button class="btn" id="btnSave" onclick="save()">提交保存</button>
				<input name="btnReturn" type="button" value="返回上一页"
					class="btn yellow" onclick="javascript:history.back(-1);" />
			</div>
		</div>
		<!--/工具栏-->
	</div>
	<input type="hidden" id="code" value="${code}" />
	<input type="hidden" id="action" value="${action}" />
	<script
		src="${pageContext.request.contextPath}/assets/js/jquery-1.11.2.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/jquery.easyui.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"
		charset="utf-8" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/assets/js/common.js" 
	    type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var action = $('#action').val();
		var contextPath = '<%=request.getContextPath()%>';
		$(function() {
			if (action == 'add'){
				$('.content-tab-ul-wrap a').html('新增科室');
				$('#CODE').removeAttr("disabled");
			}
			else{
				$('.content-tab-ul-wrap a').html('修改科室');
				$('#CODE').attr("disabled","disabled");
				var code=$('#code').val();
				setVal(code);
			}		
			//校验新增科室编码是否已经存在
 			$('#CODE').blur(function(){
				if(action=='add'){
					if(!$.isNullOrEmpty($('#CODE').val())){
						$.ajax({
							url : contextPath + "/bg/DT103.do", 
							data : {"code":$('#CODE').val(),"rnd":Math.random()},
							dataType : 'json',
							success : function(data, textStatus, jqXHR) {
								if(data.status=='true'){
									$.messager.show({title:'提示',msg:'科室编码已存在！',showType:'slide'});
									$('#CODE').val('');
									$('#CODE').focus();
								}
							}
						});
					}
				}
			}); 
			
		})
		//保存
		function save(){
			var param={};
			param.CODE = $('#CODE').val();
	  		if($.isNullOrEmpty(param.CODE)){
	  			$.messager.show({title:'提示',msg:'科室编码不能为空！',showType:'slide'});
	  			$('#CODE').focus();
	  			return;
	  		}
			param.NAME = $('#NAME').val();
	  		if($.isNullOrEmpty(param.NAME)){
	  			$.messager.show({title:'提示',msg:'科室名称不能为空！',showType:'slide'});
	  			$('#NAME').focus();
	  			return;
	  		}
			param.AUTHOR=$('#AUTHOR').val();
			param.TITLE = $('#TITLE').val();
			if(param.TITLE.length>250){
				$.messager.alert('警告','标题过长，超过250个字符！');
				return;
			}
			param.CONTENT=$('#CONTENT').val();
			if(param.CONTENT.length>2000){
				$.messager.alert('警告','科室简介过长，超过2000个字符！');
				return;
			}
			param.RND=Math.random();
			param.action=action;
			$.ajax({
				url : contextPath + "/bg/DT102.do",
				data : param,
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {
					if(data.status=='true'){
						$.messager.show({title:'提示',msg:'保存成功！',showType:'slide'});
						//location.href=contextPath+"/bg/dynamic.do";
					}else{
						$.messager.show({title:'提示',msg:'保存失败！',showType:'slide'});
					}
				}
			})
		}
		//赋值
		function setVal(code){
			$.ajax({
				url : contextPath + "/bg/DT103.do",
				data : {"code":code,"rnd":Math.random()},
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {
					var result=data.result;
					$('#CODE').val(result.CODE);
					$('#NAME').val(result.NAME);
					$('#AUTHOR').val(result.AUTHOR);
					$('#TITLE').val(result.TITLE);
					$('#CONTENT').val(result.CONTENT);
				}
			})
		}
	</script>
</body>
</html>